package com.hjm.project.download.controller;

import java.util.List;

import com.hjm.project.download.domain.Download;
import com.hjm.project.download.service.IDownloadService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * app下载记录Controller
 * 
 * @author generator
 * @date 2020-11-26
 */
@Controller
@RequestMapping("/download")
public class DownloadController extends BaseController
{
    private String prefix = "download";

    @Autowired
    private IDownloadService downloadService;

    @RequiresPermissions("download:view")
    @GetMapping()
    public String download()
    {
        return prefix + "/download";
    }

    /**
     * 查询app下载记录列表
     */
    @RequiresPermissions("download:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Download download)
    {
        startPage();
        List<Download> list = downloadService.selectDownloadList(download);
        return getDataTable(list);
    }

    /**
     * 导出app下载记录列表
     */
    @RequiresPermissions("download:export")
    @Log(title = "app下载记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Download download)
    {
        List<Download> list = downloadService.selectDownloadList(download);
        ExcelUtil<Download> util = new ExcelUtil<Download>(Download.class);
        return util.exportExcel(list, "download");
    }

    /**
     * 新增app下载记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存app下载记录
     */
    @RequiresPermissions("download:add")
    @Log(title = "app下载记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Download download)
    {
        return toAjax(downloadService.insertDownload(download));
    }

    /**
     * 修改app下载记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Download download = downloadService.selectDownloadById(id);
        mmap.put("download", download);
        return prefix + "/edit";
    }

    /**
     * 修改保存app下载记录
     */
    @RequiresPermissions("download:edit")
    @Log(title = "app下载记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Download download)
    {
        return toAjax(downloadService.updateDownload(download));
    }

    /**
     * 删除app下载记录
     */
    @RequiresPermissions("download:remove")
    @Log(title = "app下载记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(downloadService.deleteDownloadByIds(ids));
    }
}
